<?php
namespace api\modules\merchant\models;

use yii\base\Model;
use common\models\store\Store;

/**
 * Class StoreCreateForm
 * @package frontend\models
 */
class StoreCreateForm extends Model
{
    public $name;
    public $member_id;
    public $provinces;
    public $city;
    public $area;
    public $address;

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'address'], 'trim'],
            [['name', 'member_id', 'provinces','city','area','address'], 'required'],
            ['name', 'string', 'max' => 20],
            ['address', 'string', 'max' => 100],
            [['member_id', 'provinces', 'city', 'area'], 'integer'],
        ];
    }

    public function attributeLabels()
    {
        return [
            'name' => '店铺名称',
            'member_id' => '用户id',
            'provinces' => '省',
            'city' => '市',
            'area' => '区',
            'address' => '具体地址',
        ];
    }

    /**
     * 注册
     *
     * @return Store |null
     * @throws \yii\base\Exception
     */
    public function storeCreate()
    {
        $user = new Store();
        $user->username = $this->username;
        $user->email = $this->email;

        return $user->save() ? $user : null;
    }

}
